package com.leadnews.mapper;

import com.leadnews.pojo.Message;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.leadnews.vo.MessageVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author 自己
* @description 针对表【message】的数据库操作Mapper
* @createDate 2023-01-25 10:53:57
* @Entity com.leadnews.pojo.MessageVo
*/
public interface MessageMapper extends BaseMapper<Message> {
    @Select("SELECT m.id,m.create_time,m.content_last,m.user_id,m.receiver,new.name,new.picture,m.update_time FROM " +
            "           message m, (SELECT l.name,l.picture,l.user_id FROM level l where l.user_id in (SELECT m.user_id FROM message m where m.receiver=#{id}) or l.user_id in (SELECT m.receiver FROM message m where m.user_id=#{id}))" +
            " new where new.user_id=m.receiver and m.user_id=#{id} or new.user_id=m.user_id and m.receiver=#{id}" +
            " ORDER BY m.update_time desc")
    List<MessageVo> findMessage(@Param("id") int id);
}




